package io.renren.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.dao.DishFlavorDao;
import io.renren.common.dto.DishFlavorDTO;
import io.renren.common.entity.DishFlavorEntity;
import io.renren.common.service.DishFlavorService;

import io.renren.common.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.NumberUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 菜品口味关系表
 *
 * @author yidian ${email}
 * @since 1.0.0 2022-11-06
 */
@Service
public class DishFlavorServiceImpl extends CrudServiceImpl<DishFlavorDao, DishFlavorEntity, DishFlavorDTO> implements DishFlavorService {

    @Autowired
    private DishFlavorDao dishFlavorDao;
    @Override
    public QueryWrapper<DishFlavorEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String dishId = (String)params.get("dishId");

        QueryWrapper<DishFlavorEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);
        wrapper.eq(StringUtils.isNotBlank(dishId), "dish_id", dishId);
        return wrapper;
    }


    @Override
    public void deleteByDishId(Long[] dishId) {
        QueryWrapper<DishFlavorEntity> wrapper = new QueryWrapper<>();
        for (Long aLong : dishId) {
                wrapper.eq(StringUtils.isNotBlank(String.valueOf(aLong)), "dish_id", aLong);
                 dishFlavorDao.delete(wrapper);
        }

    }
}